var Submit = Class.create();

Object.extend(Submit, {
  singleSubmitLock: false,
  currentForm: null,
  
  lock: function() {
    Submit.singleSubmitLock = true;
  },
  unlock: function() {
    Submit.singleSubmitLock = false;
  },
  
  genericSubmit: function(form) {
    if (Submit.singleSubmitLock) 
      return false; 
    else {
      Submit.lock(); 
      Submit.currentForm = form;

      if (form) {
        error_container = form.down('.errors');
        loading_container = form.down('.loading');
        
        if (error_container) error_container.update(''); 
        if (loading_container) loading_container.show(); 
        
        // Clear out dormant inputs before submit
        inputs = Form.getElements(form); 
        inputs.each(function(input) {
          if (input.hasClassName('dormant')) 
            input.value = '';
          if (input.hasClassName('guid'))
            input.value = Guid.get();
        });
      }
    }
      
    return true;
  },
  
  genericAfterSubmit: function(form) {
    Submit.unlock(); 
    //Submit.currentForm = null;
    if (form) {
      loading_container = form.down('.loading');
      if (loading_container) loading_container.hide(); 
    }
  },
  
  updateErrors: function(errors) {
    if (Submit.currentForm) {
      error_container = Submit.currentForm.down('.errors');
      if (error_container) error_container.update(errors); 
    }
  }
  
});